package com.gopay.bis.service.bank.impl.expay;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.gopay.common.util.sigh.CallCashierSignUtil;
import com.gopay.remote.cashier.bis.CashierBgNotifyRemoteService;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gopay.bis.dao.bankorder.BankContractSerialInfoDAO;
import com.gopay.bis.manager.bank.BankOrderManager;
import com.gopay.bis.service.bank.BankAuthOrderService;
import com.gopay.common.Result;
import com.gopay.common.constants.bank.BankOrderStatus;
import com.gopay.common.constants.bank.CmbcConstants;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BankAuthOrder;
import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.domain.bank.cmbc.expay.CmbcExPayMessage;
import com.gopay.common.domain.bis.BisBankContractSerialInfo;
import com.gopay.common.domain.cps.vo.CPSRequest;
import com.gopay.common.domain.cps.vo.CPSResponse;
import com.gopay.common.exception.GopayException;
import com.gopay.common.util.HttpTransport;
import com.gopay.common.util.RSAEncoderUtil;
import com.gopay.common.util.TransUtil;
import com.gopay.remote.bank.BisExPayRevBankRemoteService;
import com.gopay.remote.cps.dispatch.CPSCallRemoteService;
import com.gopay.remote.cps.vo.Trans00664RemoteVo;

/**
 * 
 * 民生代扣bis接收bank异步通知service
 * 
 * @author lilili
 * @data
 */
@Service("bisExPayRevBankService")
public class BisExPayRevBankServiceImpl implements BisExPayRevBankRemoteService {

	private static Logger logger = LoggerFactory
			.getLogger(BisExPayRevBankServiceImpl.class);

	@Resource(name = "bankContractSerialInfoDAO")
	private BankContractSerialInfoDAO bankContractSerialInfoDAO;

	@Resource(name = "notifyCashier")
	private HttpTransport notifyCashier;

	@Resource(name = "cashierBgNotifyRemoteService")
	private CashierBgNotifyRemoteService cashierBgNotifyRemoteService;

	@Resource(name = "bankOrderManager")
	private BankOrderManager bankOrderManager;

	@Resource(name = "bankAuthOrderService")
    private BankAuthOrderService bankAuthOrderService;
	
	@Resource(name = "cpsCallRemoteService")
	private CPSCallRemoteService cpsCallRemoteService;
	
	public void revBankResult(Result result) {
		CmbcExPayMessage resMsg = (CmbcExPayMessage) result.getModel("res");
		if (resMsg == null) {
			logger.error("------BisExPayRevBankServiceImpl return msg is null---");
        } else {
            if (CmbcConstants.CMBCADPAY_CERTIFICATION.equals(resMsg.getTxnCode())) {
                certificationBack(result, resMsg);
            } else if (CmbcConstants.CMBCADPAY_WHITELIST.equals(resMsg.getTxnCode())) {
                whiteListBack(result, resMsg);
            } else if (CmbcConstants.CMBCADPAY_CROSS_PAYMENT.equals(resMsg.getTxnCode())
                    || CmbcConstants.CMBCADPAY_PAYMENT.equals(resMsg.getTxnCode())) {
                paymentBack(result, resMsg);
            } else if (CmbcConstants.CMBCADPAY_CROSS_QUERY.equals(resMsg.getTxnCode())
                    || CmbcConstants.CMBCADPAY_QUERY.equals(resMsg.getTxnCode())) {
                queryBack(result, resMsg);
            } else if (CmbcConstants.CMBCADPAY_CERTIFICATION_QUERY.equals(resMsg.getTxnCode())) {
                queryCertificationBack(result, resMsg);
            } else {
                logger.error("------BisExPayRevBankServiceImpl 银行返回未知交易码---");
            }
        }
	}

	/**
	 * 鉴权
	 * @param result
	 * @param resMsg
	 */
	public void certificationBack(Result result, CmbcExPayMessage resMsg) {
		if (result.isSuccess()) {
			if (resMsg.isFlag()
					&& CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg
							.getRetType())
					&& CmbcConstants.VALIDATE_STATUS_SUCCESS.equals(resMsg
							.getValidStatus())) {
				BisBankContractSerialInfo bisBankContractInfo = new BisBankContractSerialInfo();
				bisBankContractInfo.setContractState("01");
				bisBankContractInfo.setSerialNumber(resMsg.getBankOrderId());
				bankContractSerialInfoDAO
						.updateContractStateBySerialNum(bisBankContractInfo);
			} else {
				logger.error("------BisExPayRevBankServiceImpl  certificate return fail---"
						+ resMsg.getBankOrderId());
			}
		}
	}

	/**
	 * 白名单
	 * @param result
	 * @param resMsg
	 */
	public void whiteListBack(Result result, CmbcExPayMessage resMsg) {
		if (result.isSuccess()) {
			if (resMsg.isFlag()
					&& CmbcConstants.WHITELIST_STATUS_SUCCESS.equals(resMsg
							.getRetCode())
					|| CmbcConstants.WHITELIST_STATUS_REPEAT.equals(resMsg
							.getRetCode())) {
				BisBankContractSerialInfo bisBankContractInfo = new BisBankContractSerialInfo();
				bisBankContractInfo.setContractState("01");
				bisBankContractInfo.setSerialNumber(resMsg.getBankOrderId());
				bankContractSerialInfoDAO
						.updateContractStateBySerialNum(bisBankContractInfo);
			} else {
				logger.error("------BisExPayRevBankServiceImpl whiteList return fail---"
						+ resMsg.getBankOrderId());
			}
		}
	}

	/**
	 * 支付
	 * @param result
	 * @param resMsg
	 */
	public void paymentBack(Result result, CmbcExPayMessage resMsg) {
		try {
			if (!result.isSuccess()) {// 处理失败
				logger.error("BisExPayRevBankServiceImpl payment Exception:"
						+ result.getResultCode());
			}
			BankOrder bankOrder = null;
			String bankRetCode = result.getBankRetCode();//银行应答码
            bankOrder = bankOrderManager.getBankOrderById(resMsg
                    .getBankOrderId());
            if (bankOrder == null) {
                throw new GopayException(
                        ProcCodeConstants.PROC_CODE_100E5041);
            }

			Map<String, String> param = new HashMap<String, String>();
			if (!result.isSuccess()) {
				// 操作异常
				param.put("orderId", bankOrder.getOrderId());
				// 民生代扣响应报文无金额字段 add by zhengxue 20161221
				param.put("amt", bankOrder.getSendBankAmt().toString());
				param.put("cardType", "Unknown");
				param.put("notifyNum", "1");
				param.put("payStatus", "01");
				param.put("retCode", "01");
				param.put("retMsg", "验签失败");
				param.put("signData", "");
				param.put("isFront", "false");
				if(StringUtils.isNotBlank(bankRetCode)){
					//add by liuyu, 20170803, 快捷API失败通知
					bankOrder.setBankRespCode(bankRetCode);
				}
				bankOrderManager.updateBackVerifyFail(bankOrder.getOrderId());
				logger.error(bankOrder.getBankCode()
						+ " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
						+ bankOrder.getOrderId()
						+ "】失败，bis_bank_main_order表更新失败状态");
				param.put("sign", signRes(param));
				/*notifyCashier.submit(param);*/ //生产优化10期 lx 2017-9-30 16:23:37
				cashierBgNotifyRemoteService.callBgNotify(param);
				return;
			}
			if (result.isSuccess()) {
				if (resMsg.isFlag()) {
					if (CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg
							.getRetType())
							&& CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg
									.getRetCode())) {
						param.put("orderId", bankOrder.getOrderId());
						param.put("amt", bankOrder.getSendBankAmt().toString());
						param.put("cardType", "Unknown");
						param.put("notifyNum", "1");
						param.put("payStatus", "00");
						param.put("retCode", "00");
						param.put("retMsg", "验签成功");
						param.put("signData", "");
						param.put("isFront", String.valueOf(false));
						
						// 民生代扣响应报文无金额字段 add by zhengxue 20161221
//						if (bankOrder.getSendBankAmt() != null
//								&& bankOrder.getSendBankAmt().compareTo(
//										resMsg.getAmount()) != 0) {
//							// 银行返回金额与平台上送金额不符
//							bankOrderManager
//									.updateAmountError(bankOrder.getOrderId());
//							logger.error(bankOrder.getBankCode()
//									+ " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
//									+ bankOrder.getOrderId() + "】金额比对异常");
//							// SendSmsUtils.sendSmsErr(smsConfig.get("switch"),
//							// smsConfig.get("mobile"),"注意!!!订单金额不一致,银行:"+resMsg.getOutStlmCd()+"orderId:"+param.get("orderId"));
//							return;
//						}
						bankOrderManager
								.updateBackSuccess(param.get("orderId"));
						logger.error(bankOrder.getBankCode()
								+ " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
								+ bankOrder.getOrderId()
								+ "】支付成功，bis_bank_main_order表更新成功状态");
						param.put("sign", signRes(param));
						logger.error("BisExPayRevBankServiceImpl notify cashier: "
								+ param);
						/*notifyCashier.submit(param);*/ //生产优化10期 lx 2017-9-30 16:24:35
						cashierBgNotifyRemoteService.callBgNotify(param);
					} else if (CmbcConstants.RESP_TYPE_ERROR.equals(resMsg
                            .getRetType())) {
					    param.put("orderId", bankOrder.getOrderId());
                        param.put("amt", bankOrder.getSendBankAmt().toString());
                        param.put("cardType", "Unknown");
                        param.put("notifyNum", "1");
                        param.put("payStatus", "01");
                        param.put("retCode", "01");
                        param.put("retMsg", resMsg.getRetMsg());
                        param.put("signData", "");
                        param.put("isFront", String.valueOf(false));
                        param.put("sign", signRes(param));
                        
                        bankOrder.setOrderStatus(BankOrderStatus.ORDER_FAIL);
						if(StringUtils.isNotBlank(bankRetCode)){
							//add by liuyu, 20170803, 快捷API失败通知
							bankOrder.setBankRespCode(bankRetCode);
						}
                        bankOrderManager.updateBankOrder(bankOrder);
						logger.error(bankOrder.getBankCode()
								+ " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
								+ bankOrder.getOrderId() + "】验签成功订单失败");
						/*notifyCashier.submit(param);*/ //生产优化10期 lx 2017-9-30 16:25:07
						cashierBgNotifyRemoteService.callBgNotify(param);
					} else {
					    logger.error(bankOrder.getBankCode()
                                + " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
                                + bankOrder.getOrderId() + "】验签成功订单未成功");
					}
				} else {
					if(StringUtils.isNotBlank(bankRetCode)){
						//add by liuyu, 20170803, 快捷API失败通知
						bankOrder.setBankRespCode(bankRetCode);
					}
					bankOrderManager.updateBackVerifyFail(bankOrder.getOrderId());
					logger.error(bankOrder.getBankCode()
							+ " BisExPayRevBankServiceImpl payment 返回处理结果：国付宝订单号【"
							+ bankOrder.getOrderId()
							+ "】验签失败，bis_bank_main_order表更新失败状态");
				}

			}
		} catch (Exception e) {
			logger.error(resMsg.getBankOrderId()
					+ " BisExPayRevBankServiceImpl payment error", e);
		}

	}

	/**
	 * 交易查询
	 * @param result
	 * @param resMsg
	 */
	public void queryBack(Result result, CmbcExPayMessage resMsg) {
		try {
			if (!result.isSuccess()) {// 处理失败
				logger.error("BisExPayRevBankServiceImpl query Exception:"
						+ result.getResultCode());
				return;
			}
			BankOrder bankOrder = null;
			String bankRetCode = result.getBankRetCode();
	        bankOrder = bankOrderManager.getBankOrderById(resMsg.getBankOrderId());
	        if (bankOrder == null) {
	            throw new GopayException(
	                    ProcCodeConstants.PROC_CODE_100E5041);
	        }
			Map<String, String> param = new HashMap<String, String>();

            String amt = ""; // 支付金额
            if (resMsg.getOriAmt() == null || resMsg.getOriAmt().equals("")) {
                // 跨行查询返回无金额字段
                amt = bankOrder.getSendBankAmt().toString();
            } else {
                amt = TransUtil.amountConvert2Yuan(resMsg.getOriAmt());
            }
			if (result.isSuccess()) {
				if (resMsg.isFlag()) {
					if (CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg
							.getRetType())
							&& CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg
									.getRetCode())
							&& CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg
									.getOriRetType())
							&& CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg
									.getOriRetCode())) {
						param.put("orderId", bankOrder.getOrderId());
						param.put("amt", amt);
						param.put("cardType", "Unknown");
						param.put("notifyNum", "1");
						param.put("payStatus", "00");
						param.put("retCode", "00");
						param.put("retMsg", "验签成功");
						param.put("signData", "");
						param.put("isFront", String.valueOf(false));
						
						if (bankOrder.getSendBankAmt() != null
								&& bankOrder.getSendBankAmt().compareTo(
										new BigDecimal(amt)) != 0) {
							if(StringUtils.isNotBlank(bankRetCode)){
								//add by liuyu, 20170803, 快捷API失败通知
								bankOrder.setBankRespCode(bankRetCode);
							}
							// 银行返回金额与平台上送金额不符
							bankOrderManager
									.updateAmountError(bankOrder.getOrderId());
							logger.error(bankOrder.getBankCode()
									+ " BisExPayRevBankServiceImpl query 返回处理结果：国付宝订单号【"
									+ bankOrder.getOrderId() + "】金额比对异常");
							// SendSmsUtils.sendSmsErr(smsConfig.get("switch"),
							// smsConfig.get("mobile"),"注意!!!订单金额不一致,银行:"+resMsg.getOutStlmCd()+"orderId:"+param.get("orderId"));
							return;
						}
						
						// 更新订单状态
						bankOrderManager.updateQueryBackSuccess(bankOrder,
								BankOrderStatus.AUTO_CHECK_SUCCESS);
						logger.error("民生代扣支付订单：" + bankOrder.getOrderId()
								+ "的交易成功" + "返回码：" + resMsg.getOriRetCode()
								+ "返回信息：" + resMsg.getOriRetMsg());
						param.put("sign", signRes(param));
						logger.error("BisExPayRevBankServiceImpl notify cashier: "
								+ param);
						/*notifyCashier.submit(param);*/ //生产优化10期 lx 2017-9-30 16:24:35
						cashierBgNotifyRemoteService.callBgNotify(param);
					} else if (CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg
							.getRetType())
							&& CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg
									.getRetCode())
							&& CmbcConstants.RESP_TYPE_ERROR.equals(resMsg
									.getOriRetType())
							&& !CmbcConstants.EXEC_CODE_NOTEXIST.equals(resMsg
									.getOriRetCode())) {

						if(StringUtils.isNotBlank(bankRetCode)){
							//add by liuyu, 20170803, 快捷API失败通知
							bankOrder.setBankRespCode(bankRetCode);
						}
						// 银行返回失败 add by zhengxue 20161221
						bankOrderManager.updateFail(bankOrder);

					    param.put("orderId", bankOrder.getOrderId());
                        param.put("amt", amt);
                        param.put("cardType", "Unknown");
                        param.put("notifyNum", "1");
                        param.put("payStatus", "01");
                        param.put("retCode", "01");
                        param.put("retMsg", resMsg.getOriRetMsg());
                        param.put("signData", "");
                        param.put("isFront", String.valueOf(false));
                        param.put("sign", signRes(param));
                        
						logger.error("民生代扣支付订单：" + bankOrder.getOrderId()
								+ "的交易失败" + "返回码：" + resMsg.getOriRetCode()
								+ "返回信息：" + resMsg.getOriRetMsg());
						logger.error("BisExPayRevBankServiceImpl fail notify cashier: "
                                + param);
                        /*notifyCashier.submit(param);*/ //生产优化10期 lx 2017-9-30 16:24:35
						cashierBgNotifyRemoteService.callBgNotify(param);
					} else {
						logger.error("民生代扣支付订单：" + bankOrder.getOrderId()
								+ "的交易未知，系统暂不处理" + "返回码："
								+ resMsg.getOriRetCode() + "返回信息："
								+ resMsg.getOriRetMsg());
					}
				} else {
					if(StringUtils.isNotBlank(bankRetCode)){
						//add by liuyu, 20170803, 快捷API失败通知
						bankOrder.setBankRespCode(bankRetCode);
					}
					bankOrderManager.updateQueryBackVerifyFail(bankOrder);
					logger.error(bankOrder.getBankCode()
							+ " BisExPayRevBankServiceImpl query 返回处理结果：国付宝订单号【"
							+ bankOrder.getOrderId()
							+ "】验签失败，bis_bank_main_order表更新失败状态");
				}
			}
		} catch (Exception e) {
			logger.error(resMsg.getBankOrderId()
					+ " BisExPayRevBankServiceImpl query error", e);
		}

	}
	
    public void queryCertificationBack(Result result, CmbcExPayMessage resMsg) {
        try {
            if (!result.isSuccess()) {
                // 操作异常
                logger.error("BisExPayRevBankServiceImpl queryCertificationBack Exception:" + result.getResultCode());
                return;
            }
            BankAuthOrder bankAuthOrder = null;
            bankAuthOrder = bankAuthOrderService.getAuthBankOrderByBankId(resMsg.getBankOrderId());
            if (bankAuthOrder == null) {
                throw new GopayException(ProcCodeConstants.PROC_CODE_100E5041);
            }

            resMsg.setOrderId(bankAuthOrder.getOrderId()); // 赋值gopayOrderId
            Trans00664RemoteVo vo00664 = new Trans00664RemoteVo();
            if (result.isSuccess()) {
                if (resMsg.isFlag()) {
                    if (CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg.getRetType())
                            && CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg.getRetCode())
                            && CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg.getOriRetType())
                            && CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg.getOriRetCode())
                            && CmbcConstants.VALIDATE_STATUS_SUCCESS.equals(resMsg.getValidStatus())) {
                        // 更新认证主订单为认证通过
                        logger.error("民生代扣鉴权查询订单：" + bankAuthOrder.getOrderId() + "的交易成功" + "返回码："
                                + resMsg.getOriRetCode() + "返回信息：" + resMsg.getOriRetMsg() + "鉴权状态："
                                + resMsg.getValidStatus());

                        // 通知cps认证结果
                        vo00664.setResultSuccess(true);
                        vo00664.setGopayOrderId(bankAuthOrder.getOrderId());
                        vo00664.setFlag(true);
                        CPSResponse cpsres = callByVOTicket(vo00664);
                        logger.error("BisExPayRevBankServiceImpl queryCertificationBack success notify cps res: "
                                + ToStringBuilder.reflectionToString(cpsres));
                        if (ProcCodeConstants.PROC_CODE_400DS014.equals(cpsres.getRespCode())) {
                            // 通知cps成功更新鉴权状态
                            bankAuthOrderService.updateAutoQuerySuccess(resMsg);
                        }
                    } else if (CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg.getRetType())
                            && CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg.getRetCode())
                            && CmbcConstants.RESP_TYPE_SUCCESS.equals(resMsg.getOriRetType())
                            && CmbcConstants.EXEC_CODE_SUCCESS.equals(resMsg.getOriRetCode())
                            && CmbcConstants.VALIDATE_STATUS_FAIL.equals(resMsg.getValidStatus())) {
                        // 更新认证表为认证失败
                        bankAuthOrderService.updateAutoQueryFail(resMsg);
                        logger.error("民生代扣鉴权查询订单：" + bankAuthOrder.getOrderId() + "的交易失败" + "返回码："
                                + resMsg.getOriRetCode() + "返回信息：" + resMsg.getOriRetMsg() + "鉴权状态："
                                + resMsg.getValidStatus());

                        // 通知cps认证结果
                        vo00664.setResultSuccess(true);
                        vo00664.setGopayOrderId(bankAuthOrder.getOrderId());
                        vo00664.setFlag(false);
                        CPSResponse cpsres = callByVOTicket(vo00664);
                        logger.error("BisExPayRevBankServiceImpl queryCertificationBack fail notify cps res: "
                                + ToStringBuilder.reflectionToString(cpsres));
                        if (ProcCodeConstants.PROC_CODE_400DS014.equals(cpsres.getRespCode())) {
                            // 通知cps成功更新鉴权状态
                            bankAuthOrderService.updateAutoQuerySuccess(resMsg);
                        }
                    } else {
                        logger.error("民生代扣鉴权查询订单：" + bankAuthOrder.getOrderId() + "的交易未知，系统暂不处理" + "返回码："
                                + resMsg.getOriRetCode() + "返回信息：" + resMsg.getOriRetMsg());
                    }
                } else {
                    bankAuthOrderService.updateBackVerifyFail(resMsg);
                    logger.error("BisExPayRevBankServiceImpl queryCertificationBack 返回处理结果：国付宝订单号【"
                            + bankAuthOrder.getOrderId() + "】验签失败，BIS_BANK_AUTH_ORDER表更新失败状态");
                }
            }
        } catch (GopayException e) {
            logger.error(resMsg.getBankOrderId() + " BisExPayRevBankServiceImpl queryCertificationBack error", e);
        } catch (Exception e) {
            logger.error(resMsg.getBankOrderId() + " BisExPayRevBankServiceImpl queryCertificationBack error", e);
        }

    }

	/**
	 * 通知cashier签名
	 * 
	 * @param res
	 * @return
	 */
	public String signRes(Map res) {
		StringBuffer sign = new StringBuffer();
		String orderId = (String) res.get("orderId");
		String amt = (String) res.get("amt");
		String retCode = (String) res.get("retCode");
		String retMsg = (String) res.get("retMsg");
		String payStatus = (String) res.get("payStatus");
		String notifyNum = (String) res.get("notifyNum");
		String cardType = (String) res.get("cardType");
		sign.append(orderId).append("|");
		sign.append(amt).append("|");
		sign.append(retCode).append("|");
		/**** modify by sh.jiao 20170816 把英文括号转换成中文括号 start****/
		//sign.append(retMsg).append("|");
		sign.append(CallCashierSignUtil.replaceChar(retMsg)).append("|");
		/**** modify by sh.jiao 20170816 把英文括号转换成中文括号 end****/
		sign.append(payStatus).append("|");
		sign.append(notifyNum).append("|");
		sign.append(cardType);
		logger.error("bis expay通知cashier签名明文: " + sign.toString());
		try {
			return RSAEncoderUtil.sign(sign.toString());
		} catch (Exception e) {
			logger.error("bis expay通知cashier签名异常", e);
		}
		return "";
	}
	
    private CPSResponse callByVOTicket(Object v) throws GopayException {
        CPSResponse response = null;
        try {
            // 封装调用cps服务的请求baggage
            Map<String, Object> baggage = new HashMap<String, Object>();
            baggage.put("s", "0");
            baggage.put("t", "001");
            baggage.put("v", v);

            // 封装cps请求对象
            CPSRequest request = new CPSRequest();
            request.setSequence(System.currentTimeMillis());
            request.setReqData(baggage);

            // 调用cps服务
            response = cpsCallRemoteService.callCPS(request);

            // 校验调用序列值是否相同
            if (response.getSequence() != request.getSequence()) {
                throw new GopayException(ProcCodeConstants.PROC_CODE_100F3001);
            }

        } catch (Exception e) {
            logger.error("通知cps异常！！！", e);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100F3001);
        }
        return response;
    }

}
